package everyday.leetcode;

/**
 * @Author: wenjingyuan
 * @Date: 2022/09/28/10:26
 * @Description:面试题 17.09. 第 k 个数
 * https://leetcode.cn/problems/get-kth-magic-number-lcci/
 */
public class Num1709 {
    public int getKthMagicNumber(int k) {
        int[] num=new int[k];
        int p3=0,p5=0,p7=0;
        num[0]=1;
        for (int i = 1; i < k; i++) {
            num[i]=Math.min(Math.min(num[p3]*3,num[p5]*5),num[p7]*7);
            if(num[i]==num[p3]*3)p3++;
            if(num[i]==num[p5]*5)p5++;
            if(num[i]==num[p7]*7)p7++;
        }
        return num[k-1];
    }
}
